package com.ycsj.common.manager;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.lzy.ninegrid.ImageInfo;
import com.ycsj.common.activity.ShowBigImagePreviewActivity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import me.iwf.photopicker.PhotoPicker;

/**
 * 封装的跳转图片选择器和查看大图的方法
 * Created by Administrator on 2018/1/30 0030.
 */

public class PickChooseManager {
    /**
     * 跳转到图片选的方法
     *
     * @param activity
     * @param num
     */
    public static void startPhotoPickActivity(Activity activity, int num) {
        PhotoPicker.builder()
                .setPhotoCount(num)
                .setShowCamera(true)
                .setShowGif(true)
                .setPreviewEnabled(false)
                .start(activity, PhotoPicker.REQUEST_CODE);
    }


    /**
     * 自定义跳转码的图片选择方法
     *
     * @param activity
     * @param num
     * @param requestCode
     */
    public static void startPhotoPickActivity(Activity activity, int num, int requestCode) {
        PhotoPicker.builder()
                .setPhotoCount(num)
                .setShowCamera(true)
                .setShowGif(true)
                .setPreviewEnabled(false)
                .start(activity, requestCode);
    }


    /**
     * 创建查看大图的数据集合
     *
     * @param context     上下文
     * @param showPicImgs 选择的相册图片的地址集合
     * @param position    点击跳转的位置
     */
    public static void startShowBigActivity(Context context, List<String> showPicImgs, int position) {
        // 查看大图的数据集合
        List<ImageInfo> imageInfo = new ArrayList<>();
        for (int i = 0; i < showPicImgs.size(); i++) {

            ImageInfo info = new ImageInfo();
            // 设置大图
            info.setBigImageUrl(showPicImgs.get(i));
            // 设置小图
            info.setThumbnailUrl(showPicImgs.get(i));
            imageInfo.add(info);
        }

        // 跳转到查看大图的界面
        Intent intent = new Intent(context,
                ShowBigImagePreviewActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable(ShowBigImagePreviewActivity.IMAGE_INFO,
                (Serializable) imageInfo);
        bundle.putInt(ShowBigImagePreviewActivity.CURRENT_ITEM,
                position);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }
}
